﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OpenPhotoAlbum.Controls
{
    public abstract class ListView : WebControl
    {
		public ListView()
		{
			Items = new List<ListViewItem>();
		}

        public string HeaderText { get; set; }

        public List<ListViewItem> Items { get; set; }

        private Unit _width { get; set; }

        public override Unit Width
        {
            get
            {
                return _width;
            }
            set
            {
                _width = value;
            }
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            RenderHeader(output);

            foreach (ListViewItem item in Items) { RenderItem(output, item); }

            RenderFooter(output);
        }

        protected virtual void RenderHeader(HtmlTextWriter output)
        {
			output.AddAttribute(HtmlTextWriterAttribute.Class, "listTitle");
            output.RenderBeginTag(HtmlTextWriterTag.Div);
            output.Write(HeaderText);
            output.RenderEndTag();
        }

        protected virtual void RenderItem(HtmlTextWriter output, ListViewItem item)
        {
            output.AddAttribute(HtmlTextWriterAttribute.Href, item.linkUrl);
            output.RenderBeginTag(HtmlTextWriterTag.A);

            output.AddAttribute(HtmlTextWriterAttribute.Src, item.thumbnailUrl);
            output.AddAttribute(HtmlTextWriterAttribute.Alt, item.name);
            //output.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "none");
            output.RenderBeginTag(HtmlTextWriterTag.Img);
            output.RenderEndTag();  // end of IMG

            output.RenderEndTag();  // end of A

            output.Write(" ");
        }

        protected virtual void RenderFooter(HtmlTextWriter output)
        {
        }
    }
}
